//
//  LGPatientRepetitionView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/10/23.
//

#import "LGPatientRepetitionView.h"

@interface LGPatientRepetitionView()

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UILabel *numberLabel;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *cardidLabel;
/**   */
@property (nonatomic , strong)UILabel *phoneLabel;
/**   */
@property (nonatomic , strong)UIView *lineView_H;
/**   */
@property (nonatomic , strong)UIView *lineView_V;
/**   */
@property (nonatomic , strong)UIButton *backBtn;


@end

@implementation LGPatientRepetitionView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
        [UIView animateWithDuration:0.4 animations:^{
            self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0.5];
            self.baseView.transform = CGAffineTransformScale(self.baseView.transform, 10000, 10000);
        }];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSString *resCode = LGNSString(dataDic[@"resCode"]);
    if([resCode isEqualToString:@"1"]){
        //身份证号重复
        self.titleLabel.text = @"身份证号重复";
        self.contentLabel.text = @"与下列患者身份证号重复，是否将本次填写内容更新到下列患者：";
        self.cardidLabel.textColor = [UIColor colorWithString:@"#DD3030"];
    }else if ([resCode isEqualToString:@"2"]){
        //手机号重复
        self.titleLabel.text = @"手机号重复";
        self.contentLabel.text = @"与下列患者手机号重复，是否将本次填写内容更新到下列患者：";
        self.phoneLabel.textColor = [UIColor colorWithString:@"#DD3030"];
    }
    [self.contentLabel lineSpacing:5];
    self.numberLabel.text = [NSString stringWithFormat:@"登记号：%@",dataDic[@"hospital_bano"]];
    self.nameLabel.text = [NSString stringWithFormat:@"患者姓名：%@",dataDic[@"realname"]];
    self.cardidLabel.text = [NSString stringWithFormat:@"身份证号：%@",dataDic[@"card_no"]];
    self.phoneLabel.text = [NSString stringWithFormat:@"手机号：%@",dataDic[@"mobile"]];
}

-(void)sureButtonAction{
    if(self.updatePatientInfo){
        self.updatePatientInfo();
    }
    [self closeViewAction];
}

//关闭
-(void)closeViewAction{
    [UIView animateWithDuration:0.4 animations:^{
        self.baseView.transform = CGAffineTransformScale(self.baseView.transform, 0.0001, 0.0001);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0];
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.contentLabel];
    [self.baseView addSubview:self.numberLabel];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.cardidLabel];
    [self.baseView addSubview:self.phoneLabel];
    [self.baseView addSubview:self.lineView_H];
    [self.baseView addSubview:self.lineView_V];
    [self.baseView addSubview:self.backBtn];
    [self.baseView addSubview:self.sureBtn];
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] initWithFrame:CGRectMake((Screen_W-viewPix(320))/2.0, (Screen_H-viewPix(305))/2.0, viewPix(320), viewPix(305))];
        _baseView.transform = CGAffineTransformScale(_baseView.transform, 0.0001, 0.0001);
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"身份证号重复" colorString:@"#333333" textFont:LGFontWeight(17, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _titleLabel.frame = CGRectMake(0, viewPix(27), viewPix(320), viewPix(24));
    }
    return _titleLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"与下列患者身份证号重复，是否将本次填写内容更新到下列患者：" colorString:@"#333333" textFont:LGFont(17) textAlignment:NSTextAlignmentLeft lines:0];
        _contentLabel.frame = CGRectMake(viewPix(24), viewPix(70), viewPix(273), viewPix(51));
    }
    return _contentLabel;
}

-(UILabel *)numberLabel{
    if(!_numberLabel){
        _numberLabel = [UILabel lableWithText:@"登记号：" colorString:@"#333333" textFont:LGFontWeight(17, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _numberLabel.frame = CGRectMake(viewPix(24), viewPix(127), viewPix(273), viewPix(25));
    }
    return _numberLabel;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"患者姓名：" colorString:@"#333333" textFont:LGFontWeight(17, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _nameLabel.frame = CGRectMake(viewPix(24), kMaxY(self.numberLabel.frame), viewPix(273), viewPix(25));
    }
    return _nameLabel;
}

-(UILabel *)cardidLabel{
    if(!_cardidLabel){
        _cardidLabel = [UILabel lableWithText:@"身份证号：" colorString:@"#333333" textFont:LGFontWeight(17, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _cardidLabel.frame = CGRectMake(viewPix(24), kMaxY(self.nameLabel.frame), viewPix(273), viewPix(25));
    }
    return _cardidLabel;
}

-(UILabel *)phoneLabel{
    if(!_phoneLabel){
        _phoneLabel = [UILabel lableWithText:@"手机号：" colorString:@"#333333" textFont:LGFontWeight(17, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _phoneLabel.frame = CGRectMake(viewPix(24), kMaxY(self.cardidLabel.frame), viewPix(273), viewPix(25));
    }
    return _phoneLabel;
}

-(UIView *)lineView_H{
    if(!_lineView_H){
        _lineView_H = [[UIView alloc] initWithFrame:CGRectMake(0, viewPix(249), viewPix(320), 0.5)];
        _lineView_H.backgroundColor = [UIColor colorWithString:@"#E5E5E5"];
    }
    return _lineView_H;
}

-(UIView *)lineView_V{
    if(!_lineView_V){
        _lineView_V = [[UIView alloc] initWithFrame:CGRectMake(viewPix(160), viewPix(249), 0.5, viewPix(56))];
        _lineView_V.backgroundColor = [UIColor colorWithString:@"#E5E5E5"];
    }
    return _lineView_V;
}

-(UIButton *)backBtn{
    if(!_backBtn){
        _backBtn = [UIButton buttonWithTitle:@"返回修改" titleFont:LGFont(17) textColor:@"#333333" imageName:@""];
        _backBtn.frame = CGRectMake(0, kMaxY(self.lineView_H.frame), viewPix(160), viewPix(56));
        [_backBtn addTarget:self action:@selector(closeViewAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backBtn;
}

-(UIButton *)sureBtn{
    if(!_sureBtn){
        _sureBtn = [UIButton buttonWithTitle:@"确认更新" titleFont:LGFontWeight(17, UIFontWeightMedium) textColor:@"#2E8FFF" imageName:@""];
        _sureBtn.frame = CGRectMake(viewPix(160), kMaxY(self.lineView_H.frame), viewPix(160), viewPix(56));
        [_sureBtn addTarget:self action:@selector(sureButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sureBtn;
}


@end
